<template>
    <h2>登录页面</h2>
    <table class="table table-bordered">
        <tbody>
            <tr>
                <td>用户名</td>
                <td>
                    <input type="text" v-model="form.userName">
                </td>
            </tr>
            <tr>
                <td>密码</td>
                <td>
                    <input type="password" v-model="form.pwd">
                </td>
            </tr>
            <tr>
                <td></td>
                <td>
                    <button class="btn btn-primary" @click="Add">登录</button>
                </td>
            </tr>
        </tbody>
    </table>
</template>
<script setup lang="ts">
//引入组件
import { ref, reactive, onMounted } from "vue"
//bootstrap样式
import "bootstrap/dist/css/bootstrap.min.css"
//访问后端
import axios from "axios"
//路由(1)
import { useRouter } from "vue-router";

const router = useRouter();

const form = reactive({
    id: 0,
  userName: "",
  pwd: "",
})
const Add = () => {
    if (!form.userName) {
        alert("用户名不能为空！")
        return;
    }
    if (!form.pwd) {
        alert("密码不能为空！")
        return;
    }
    axios.get("http://localhost:5145/api/Huiyuan/Login?username="+form.userName+"&password="+form.pwd).then(res => {
        if (res.data > 0) {
            alert("登录成功！！");
            router.push("/huuiYuanShow")
        }
        else {
            alert("登录失败！！！");
        }
    })
}

</script>